
#include <stdio.h>
#include "world.h"
#include "display.h"



int main( int argc, char* argv[], char* envp[] ) {
  std::string arguments;
  std::string descriptor;
  char exception_message[] = "Top level: %s\n\n";

  try {
    srand( time( NULL ) );

    for ( int i = 0; i < argc; ++i ) {
      arguments.append( argv[i] ).append( " " );
    }

    if ( Regex::match( "-copyover\\s+-fd=(\\d+)", arguments, descriptor ) ) {
        World::Instance().copyover( true );
        World::Instance().recover( estring( descriptor ) );
    } else {
      World::Instance().startup();
    }

  } catch ( SocketException se ) {
    fprintf( stderr, exception_message, se.getError().c_str() );
  } catch ( MysqlException me ) {
    fprintf( stderr, exception_message, me.getMessage().c_str() );
  } catch ( std::string s ) {
    fprintf( stderr, exception_message, s.c_str() );
  } catch ( std::exception e ) {
    fprintf( stderr, exception_message, e.what() );
  } catch ( ... ) {
    fprintf( stderr, exception_message, "uncaught" );
  }

  return EXIT_NORMAL;
}

